home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-06-30 | 10.2 KB | 314 lines | [TEXT/CWIE] |
- // ===========================================================================
- // LAGAEditField.cp
- // ===========================================================================
- // “Apple Grayscale Appearance” compliant Text Entry Field
- // Copyright © 1996 Chrisoft (Christophe ANDRES) All rights reserved.
- //
- // You may use this source code in any application (commercial, shareware, freeware,
- // postcardware, etc), but not remove this notice (no need to acknowledge the use of
- // this class in the about box)
- // You may not sell this source code in any form. This source code may be placed on
- // publicly accessable archive sites and source code disks. It may not be placed on
- // profit archive sites and source code disks without the permission of the author,
- // Christophe ANDRES.
- //
- // This source code is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- //
- // If you make any change or improvement on this class, please send the improved/changed
- // version to : chrisoft@calva.net or Christophe ANDRES
- // 20, rue Prosper Mérimée
- // 67100 STRASBOURG
- // FRANCE
- //
- // ===========================================================================
- // LAGAEditField.h <- double-click + Command-D to see class declaration
- //
- // LAGAEditField is my implementation of the “Apple Grayscale Appearance for System 7.5”
- // Text Entry field. It handles the 3D effect, but is also designed to work effectively
- // with a class like LAGAIndexTab. In an index tab, a Text Entry Field can be present but
- // in another Index Tab, and should therefore not be selected when the user presses the
- // “Tab” key. Also if the Index Tab is changed and a Text Entry Field is revealed it should
- // be selected. LAGAEditField handles all these cases.
- // LAGAEditField keeps its own background in white, whatever the window background may be.
- //
- // This class requires AGAColors.cp to be present in your project
- //
- // Version : 1.2
- //
- // Change History (most recent first, date in US form : mm/dd/yy):
- //
- // 06/30/96 ca Public release of version 1.2
- // 06/26/96 ca Changed the way the disabled state is drawn (border in real gray and text also)
- // 06/24/96 ca Added call to StColorPenState::Normalize to avoid influence on our colors
- // 06/20/96 vp Vince Parsons <vparsons@ddg.com>
- // Changed the rect erase to white to avoid an unwanted gray border
- // 06/04/96 ca Added RegisterClass method to ease registry
- // Increased version to 1.2
- // 05/20/96 ca Increased version to 1.1
- // Added copy constructor
- // Added "on the fly" constructor
- // Replaced UEnvironment::HasFeature(env_SupportsColor) with PaneInColor
- // Added change history
- // 05/10/96 M™H Changes by Michael(tm) Hamel <mhamel@adi.co.nz>
- // Corrected the fact that LAGAEditField used to draw outside of its frame, which is a problem
- // if you Hide() it.
- // Note : You might need to increase slightly (2 pixels) the height of objects created with
- // version 1.0
- // 04/22/96 ca class made available by Christophe ANDRES <chrisoft@calva.net>
- // (version 1.0)
- //
- // To Do:
- //
-
- #include "LAGAEditField.h"
- #include "AGAColors.h"
- #include <UDrawingState.h>
- #include <UEnvironment.h>
- #include <PP_Messages.h>
- #include <LView.h>
-
- // begin <06/04/96 ca>
- void LAGAEditField::RegisterClass ()
-
- {
- URegistrar::RegisterClass(LAGAEditField::class_ID, (ClassCreatorFunc)LAGAEditField::CreateAGAEditFieldStream);
- }
- // end <06/04/96 ca>
-
- LAGAEditField* LAGAEditField::CreateAGAEditFieldStream (LStream *inStream)
-
- {
- return(new LAGAEditField(inStream));
- }
-
- //-------Constructors-------------------------------------------------------------------------------------------------
-
- LAGAEditField::LAGAEditField (LStream *inStream) : LEditField (inStream)
-
- {
- AlignTextEditRects(); // Our version... <05/10/96 M™H>
- }
-
- LAGAEditField::LAGAEditField (const LAGAEditField &inOriginal) : LEditField(inOriginal)
-
- {
- AlignTextEditRects(); // Our version... <05/10/96 M™H>
- }
-
- LAGAEditField::LAGAEditField (const SPaneInfo &inPaneInfo, Str255 inString, ResIDT inTextTraitsID,
- Int16 inMaxChars, Boolean inHasBox, Boolean inHasWordWrap,
- KeyFilterFunc inKeyFilter, LCommander *inSuper)
- :LEditField(inPaneInfo, inString, inTextTraitsID, inMaxChars, inHasBox,
- inHasWordWrap, inKeyFilter, inSuper)
- {
- AlignTextEditRects(); // Our version... <05/10/96 M™H>
- }
-
- void LAGAEditField::DrawBox ()
-
- {
- Rect frame;
- Boolean hasColor = ::PaneInColor(this);
- StColorPenState saveColors;
-
- saveColors.Normalize(); // <06/24/96 ca>
- CalcLocalFrameRect(frame);
- if (hasColor)
- {
- ::RGBForeColor(&gAGAColorArray[5]);
- ::MoveTo(frame.left, frame.bottom - 2);
- ::LineTo(frame.left, frame.top);
- ::LineTo(frame.right - 2, frame.top);
- ::ForeColor(whiteColor);
- ::MoveTo(frame.left + 1, frame.bottom - 1);
- ::LineTo(frame.right - 1, frame.bottom - 1);
- ::LineTo(frame.right - 1, frame.top + 1);
- }
-
- // Inner black or gray border
- ::InsetRect(&frame, 1, 1);
- ApplyForeAndBackColors();
- if (mEnabled != triState_On)
- if (hasColor)
- ::RGBForeColor(&gAGAColorArray[8]); // <06/26/96 ca>
- else
- ::PenPat(&UQDGlobals::GetQDGlobals()->gray);
- ::FrameRect(&frame);
-
- // TextEdit area and inner border, white
- ::InsetRect(&frame, 1, 1); // <06/20/96 vp>
- ::BackColor(whiteColor);
- ::EraseRect(&frame);
- }
-
- //-------------- From LEditField, patched for 3-deep indent -------------------
-
- void LAGAEditField::DrawSelf ()
-
- {
- Rect frame;
- StColorPenState saveColors;
-
- saveColors.Normalize(); // <06/26/96 ca>
- CalcLocalFrameRect(frame);
-
- if (mHasBox) // Draw Border if necessary
- {
- DrawBox();
- ::InsetRect(&frame, 3, 3);
- }
-
- if ((mEnabled != triState_On) && ::PaneInColor(this)) // <06/26/96 ca>
- ::RGBForeColor(&gAGAColorArray[8]); // <06/26/96 ca>
-
- // A Mac TERec stores a pointer to its owner port We have to
- // change it to the current port in case we are drawing into
- // a port that is not the owner port. This happens when we are
- // printing or drawing into an offscreen port.
-
- GrafPtr savePort = (**mTextEditH).inPort;
- (**mTextEditH).inPort = UQDGlobals::GetCurrentPort();
-
- ::TEUpdate(&frame, mTextEditH);
-
- (**mTextEditH).inPort = savePort;
- }
-
- void LAGAEditField::AlignTextEditRects ()
-
- {
- Rect textFrame;
- if (!CalcLocalFrameRect(textFrame))
- {
-
- // Frame is outside QD Space. Put textFrame at the
- // upper left limit of QD Space (extreme negative coords).
- // That location is guaranteed to be offscreen (unless
- // you have a control longer than 32K pixels) since PP
- // Image coordinates start at (0,0) and are never negative.
-
- textFrame.left = min_Int16;
- textFrame.right = textFrame.left + mFrameSize.width;
- textFrame.top = min_Int16;
- textFrame.bottom = textFrame.top + mFrameSize.height;
- }
-
- if (mHasBox)
- {
- ::InsetRect(&textFrame, 3, 3); // M™H for LAGA version
- }
- // Set TextEdit view and dest rectangles
- // to be the same as the Frame
- (**mTextEditH).viewRect = textFrame;
- (**mTextEditH).destRect = textFrame;
-
- AdjustTextWidth(false);
-
- ::TECalText(mTextEditH); // Let TextEdit adjust line breaks
- }
-
- void LAGAEditField::AdjustTextWidth (Boolean inShrinkToText)
- {
- if (!mHasWordWrap) // Adjust only if WordWrap is OFF
- {
-
- Rect textFrame; // Get size of editable text area
- CalcLocalFrameRect(textFrame);
- if (mHasBox)
- {
- ::InsetRect(&textFrame, 3, 3);
- }
-
- Int16 destWidth = 4000; // Very Wide
-
- if (inShrinkToText) // Width of the Text in the EditField
- {
-
- Point startPoint = ::TEGetPoint(0, mTextEditH);
- Point endPoint = ::TEGetPoint((**mTextEditH).teLength, mTextEditH);
- destWidth = endPoint.h - startPoint.h;
-
- if (destWidth < textFrame.right - textFrame.left)
- {
- destWidth = textFrame.right - textFrame.left;
- }
- }
-
- // Direction to extend dest rect depends
- // on the text justification
- Int16 just = (**mTextEditH).just;
- if (just == teFlushDefault)
- {
- // For left justificaton, GetSysDirection
- // returns teFlushDefault
- // For right, teFlushRight
- just = ::GetSysDirection();
- }
-
- switch (just)
- {
-
- case teFlushLeft: // Text fixed on left and grows right
- case teFlushDefault:
- (**mTextEditH).destRect.right = (**mTextEditH).destRect.left + destWidth;
- break;
-
- case teFlushRight: // Text grows to the left
- (**mTextEditH).destRect.left = (**mTextEditH).destRect.right - destWidth;
- break;
-
- case teCenter:
- { // Text grows left and right
- Int16 center = (textFrame.left + textFrame.right) / 2;
- (**mTextEditH).destRect.left = center - 2000;
- (**mTextEditH).destRect.right = center + 2000;
- break;
- }
- }
- }
- }
-
- //-------------------------------------------------------------------------
-
- Boolean LAGAEditField::ObeyCommand (CommandT inCommand, void* ioParam)
-
- {
- Boolean cmdHandled = true;
-
- switch (inCommand)
- {
- case msg_TabSelect : // Often LAGAEditField items can be in tab index views and we need to be seen to be selected
- if (!IsEnabled())
- cmdHandled = false;
- else
- if (mSuperView != nil)
- {
- Rect frame;
- Rect revealedRect;
-
- CalcPortFrameRect(frame);
- mSuperView->GetRevealedRect(revealedRect);
- cmdHandled = ::SectRect(&revealedRect, &frame, &revealedRect);
- }
- if (!cmdHandled)
- break; // else fall thru to default case
- default:
- cmdHandled = LEditField::ObeyCommand(inCommand, ioParam);
- break;
- }
-
- return cmdHandled;
- }
-
- void LAGAEditField::SpendTime (const EventRecord &inMacEvent)
-
- {
- if (FocusExposed())
- ::TEIdle(mTextEditH);
- else
- SwitchTarget(GetSuperCommander());
- }
-
-